<?php 
class GoodsAttrFormModel extends Model{
	public $table="goods_type";

	public function get($gtid,$data=null){
		$AttrModel=M('attr_class');
		$AttrData=$AttrModel->where(array('gtid'=>$gtid,'is_spec'=>0))->all();
		// p($gtid);exit;
		if(empty($AttrData))return array();
		foreach ($AttrData as $n => $class) {
			$function = $class['show_type']; 
			// p($function);exit;
			if(method_exists($this, $function)){
				$field=M('attr_value')->where(array('acid'=>$class['acid'],))->all();
				$AttrData[$n]['html']=$this->$function($field,$data);
			}
		}
		return $AttrData;
	}
	public function box($fields,$data){
		$html="";
		$html.='<select name="attr['.$fields[0]['acid'].']">';
		foreach($fields as $field){
			$selected="";
			if($data){
				$selected=isset($data[$field['avid']])?"selected=''":"";
			}
			$value=$field['avid'].'|'.$field['attr_value'];
			$html.="<option value='{$value}' $selected >{$field['attr_value']}</option>";
		}
		$html.="</select>";
		return $html;
	}
	public function input($fields,$data){
		$name=$fields[0]['acid'].'|'.$fields[0]['avid'];
		$html="<input type='text' name='attr[{$name}]' value='{$fields[0]['attr_value']}'>";
		return $html;
	}


}



 ?>